//<{$lang.search}>
var paginationTotal = 1;//记录总数
var isSearch = false;
function submitsearchputaway() {
    isSearch = true;
    paginationCurrentPage = 1;
    initData(0);
}
$(function () {
    $(".searchputaway").click(function () {
        var putawayno = $("[name=putawayNo]").val();
        var dateFrom = $("[name=dateFrom]").val();
        var dateTo = $("[name=dateTo]").val();
        var qco_code = $("[name=qco_code]").val();
        var receivingNo = $("[name=receivingNo]").val();
        if (putawayno == '' && ( dateFrom == '' && dateTo == '') && receivingNo=='' && qco_code=='') {
            alertTip('<{$lang.pls_input}><{$lang.search}><{$lang.content}>!');
            return;
        }
        if (dateFrom != '' && dateTo != '') {
            submitsearchputaway();
            return;
        } else if (putawayno == ''&& receivingNo=='' && qco_code=='') {
            alertTip('<{$lang.date}><{$lang.can_not_be_empty}>');
            return;
        }
        submitsearchputaway();
    });
    <{if $lang.current_language=='cn'}>
    var dayNamesMin =['日','一', '二', '三', '四', '五', '六'];
    var monthNamesShort = ['01月','02月','03月','04月','05月','06月','07月','08月','09月','10月','11月','12月'];
    $('#dateFrom,#dateTo').datepicker({
        dayNamesMin:dayNamesMin,
        monthNamesShort:monthNamesShort,
        changeMonth:true,
        changeYear:true,
        dateFormat:'yy-mm-dd'
    });
    <{else}>
    $('#dateFrom,#dateTo').datepicker({
        changeMonth:true,
        changeYear:true,
        dateFormat:'yy-mm-dd'
    });
    <{/if}>
    $('#dateFrom,#dateTo').val(getdate());
});
function onblurputaway(obj) {
    var val=$(obj).val();
    if ($(obj).val() != '') {
        $('#dateFrom,#dateTo').val('');
        $("[name=putawayNo],[name=receivingNo],[name=qco_code]").val('');
        $(obj).val(val);
    }else{
        $('#dateFrom,#dateTo').val(getdate());
    }
}
function getdate() {
    var date = new Date();
    var now = "";
    now = date.getFullYear() + "-";
    now = now + (date.getMonth() + 1) + "-";
    now = now + date.getDate() + " ";
    return now;
}
function loadData(page, pageSize) {
    var vForm = "";
    if (isSearch == true && isSearch != undefined) {
        vForm = $("#sForm").serializeArray();
    }
    $.ajax({
        type:"POST",
        async:false,
        dataType:"json",
        url:"/product/putaway/search-putaway/page/" + page + "/pageSize/" + pageSize,
        data:vForm,
        success:function (json) {
            var html = "";
            var module = '';
            paginationTotal = json.total;
            if(page==0){page=1}
            var i = page == 1 ? 1 : pageSize * (page - 1) + 1;
            if (json.ask == 0) {
                 var err='<{$lang.no_data}>';
                if(json.error){
                    var err=json.error;
                }
                html = "<tr><td colspan='10' align='center'>"+err+"</td></tr>";
            } else {
                $.each(json.result, function (k, v) {
                    //var putaway_status = (v.putaway_status == '0') ? '<img src=\'/images/icon/unnormal.gif\'>' : '<img src=\'/images/icon/statusok.png\'>';
                    var putaway_user_id = (v.putaway_user_id == null) ? '' : v.putaway_user_id;
                    html += "<tr >"
                    html += '<td>' + (i++) + '</td>';
                    html += '<td>' + v.receiving_code + '</td><td>' + v.putaway_code + '</td><td>' + v.putaway_lot_number + '</td>';
                    html += '<td>'+v.customer_id+'-'+ v.product_sku + '</td>';
                    html += '<td>' + v.putaway_status + '</td>';
                    html += '<td>' + v.putaway_quantity + '</td>';
                    html += "<td>" + v.ws_code + "</td>";
                    html += "<td>" + putaway_user_id + "</td>";
                    html += "<td>" + v.putaway_date + "</td>";
                    html += "</tr>";
                });
            }
            $("#viewPutawaylistloadData").html(html);
            $("#viewPutawaylistloadData>tr:even").addClass('even-tr');
        }
    });
}
//<{$lang.operation}><{$lang.tip}>
function alertTip(tip) {
    $('<div title="<{$lang.tip}>" class="alertTip"><p align="center">' + tip + '</p></div>').dialog({
        modal:true,
        width:450,
        buttons:{
            '<{$lang.ok}>':function () {
                $(this).dialog("close");
            }
        }
    });
}